package com.chart.web.controller.chart;

import com.chart.chart.domian.req.VGenerateReq;

import com.chart.chart.domian.req.VerifiedReq;
import com.chart.chart.service.IChartVouchersService;
import com.chart.common.core.domain.AjaxResult;

import com.chart.common.core.domain.model.LoginUser;
import com.chart.common.utils.SecurityUtils;
import com.chart.framework.web.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "兑换码模块")
@RestController
@RequestMapping("/vouchers")
public class ChartVouchersController {

    @Autowired
    private IChartVouchersService chartVouchersService;

    @Resource
    private TokenService tokenService;

    @ApiOperation("兑换码生成")
    @PostMapping("/generate")
    public AjaxResult vouchersGenerate(@RequestBody VGenerateReq req) {
        return AjaxResult.success(chartVouchersService.generate(req.getType()));
    }
    @ApiOperation("兑换码核销")
    @PostMapping("/verified")
    public AjaxResult verified(@RequestBody VerifiedReq req){
        String token = tokenService.getTokenKey1(SecurityUtils.getLoginUser().getToken());
        return chartVouchersService.verified(req,token);
    }

}
